<?php
/**
 * 微签到模块微站定义
 *
 * @author zhouziyuan
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');

class Yuan_guagualeModuleSite extends WeModuleSite {
	public function doWebGuaguale() {
		//这个操作被定义用来呈现 功能封面
		global $_W,$_GPC;
		$murl = MODULE_URL."template/mobile/";
		include $this->template('guaguale');
	}
	public function doWebPrize() {
	    //这个操作被定义用来呈现 功能封面
	    global $_W,$_GPC;
	    $murl = MODULE_URL."template/mobile/";	        
	    if($_GPC['operation']=='add'){
	        if($_GPC['op']=='additem'){
	            if(!$_GPC['prizeimgurl']||!$_GPC['prizename']||!$_GPC['prizenumber']||!$_GPC['chance']||!$_GPC['prizetype']){
	                message("数据项不允许为空");
	            }

	            if(pdo_query('select * from'.tablename($this->modulename."_prize")." where prizename=:prizename",array('prizename'=>$_GPC['prizename']))){
	                message("礼品名不允许重复");
	            }

	            pdo_insert($this->modulename.'_prize',array('weid'=>$_W['uniacid'],'prizename'=>$_GPC['prizename'],'prizetype'=>$_GPC['prizetype'],'prizenumber'=>$_GPC['prizenumber'],'prizeimgurl'=>$_GPC['prizeimgurl'],'chance'=>$_GPC['chance']));
	            header("Location: ".$this->createWebUrl('prize'));
	        }
	    }
	    elseif($_GPC['operation']=='update'){
	    
	        if(!$_GPC['id']){
	            message("id不能为空");
	        }
	    
	        if($_GPC['op']=='updateitem'){
	            if(!$_GPC['prizeimgurl']||!$_GPC['prizename']||!$_GPC['prizenumber']||!$_GPC['chance']||!$_GPC['prizetype']){
	                message("数据项不允许为空");
	            }
	            pdo_update($this->modulename."_prize",array('prizename'=>$_GPC['prizename'],'prizetype'=>$_GPC['prizetype'],'prizenumber'=>$_GPC['prizenumber'],'chance'=>$_GPC['chance'],'prizeimgurl'=>$_GPC['prizeimgurl']),array('id'=>$_GPC['id']));
	            message('礼品修改成功',$this->createWebUrl('prize'));
	        }
	        $prizeitem = pdo_fetch("select * from ".tablename($this->modulename."_prize")." where id=:id",array('id'=>$_GPC['id']));
	    }
	    elseif($_GPC['operation']=='delete'){
	        if(!$_GPC['id']){
	            message("id不能为空");
	        }
	        pdo_delete($this->modulename."_prize",array('id'=>$_GPC['id']));;
	        message('礼品删除成功',$this->createWebUrl('prize'));
	    }
	    $page = max(1, intval($_GPC['page']));
	    $pageitem = 5;
	    $pagestart = $pageitem*($page-1);
	    $where = "";
	    if($_GPC['op']=='prizeselect'){
	        if($_GPC['prizename']){
	            $prizename=$_GPC['prizename'];
	            $where .= " and prizename like '%".$_GPC['prizename']."%'";
	        }
	        if($_GPC['prizetype']){
	            $prizetype=intval($_GPC['prizetype']);
	            $where .= " and prizetype like '%".$_GPC['prizetype']."%'";
	        }
	    }
	    $prizelist = pdo_fetchall("select * from ".tablename($this->modulename.'_prize')." where weid=:weid".$where,array('weid'=>$_W['uniacid']));
	    $itemall = count($prizelist);
	    $prizelist = pdo_fetchall("select * from ".tablename($this->modulename.'_prize')." where weid=:weid".$where." limit ".$pagestart.",".$pageitem,array('weid'=>$_W['uniacid']));
	    $pager = pagination($itemall,$page,$pageitem);
	    include $this->template('prize');
	}
	public function doWebMember() {
	    //这个操作被定义用来呈现 功能封面
	    global $_W,$_GPC;
	    $murl = MODULE_URL."template/mobile/";
	    include $this->template('member');
	}
	public function doWebHistory() {
	    //这个操作被定义用来呈现 功能封面
	    global $_W,$_GPC;
	    $murl = MODULE_URL."template/mobile/";
	    
	    include $this->template('history');
	}
}